

<template>
  <!-- 导航 -->
  <el-row style="margin: 10px;background-color: ghostwhite;padding: 15px">
    <el-col :span="24">
      <el-breadcrumb>
        <el-breadcrumb-item>首页</el-breadcrumb-item>
        <el-breadcrumb-item>生产管理</el-breadcrumb-item>
        <el-breadcrumb-item>工艺流程</el-breadcrumb-item>
      </el-breadcrumb>
    </el-col>
  </el-row>
  <!-- 搜索栏-->
  <el-row style="margin: 10px;padding: 15px">
    <el-col :span="24">
      <el-form :model="workmanshipQuery" inline>
        <el-form-item label="工序编码">
          <el-input v-model="workmanshipQuery.workmanshipRouteId">
          </el-input>
        </el-form-item>
        <el-form-item label="工序名称">
          <el-input v-model="workmanshipQuery.workmanshipRouteName"/>
        </el-form-item>
        <el-form-item label="是否启用">
          <el-select style="width: 100px" v-model="workmanshipQuery.workmanshipStatus">
            <el-option :value="0" label="全部"/>
            <el-option :value="1" label="是"/>
            <el-option :value="2" label="否"/>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button @click="loadWorkmanship" type="primary"><el-icon><Search /></el-icon>搜索</el-button>
          <el-button @click="clearAll"><el-icon><Refresh /></el-icon>清空</el-button>
        </el-form-item>
      </el-form>
    </el-col>
  </el-row>
  <!-- 工具栏 -->
  <el-row style="margin: 0px 10px;padding: 0px 10px">
    <el-col :span="24">
      <el-button @click="addWorkmanship" type="primary" plain><el-icon><Plus /></el-icon>新增</el-button>
      <el-button @click="" type="success" plain><el-icon><EditPen /></el-icon>修改</el-button>
      <el-button @click="reDelete" type="danger" plain><el-icon><Delete /></el-icon>删除</el-button>
      <el-button @click="" type="warning" plain><el-icon><Download /></el-icon>导出</el-button>
    </el-col>
  </el-row>
  <!-- 数据列表 -->
  <el-row style="margin: 10px 10px;padding:0px 15px;">
    <el-col :span="24">
      <el-table :data="workmanships" border stripe ref="workmanshipTable">
        <el-table-column type="selection" width="55"/>
        <el-table-column prop="workmanshipRouteId" label="工艺路线编码">
          <template #default="scope">
            <el-link type="success" @click="showDetails(scope.row)">{{scope.row.workmanshipRouteId}}</el-link>
          </template>
        </el-table-column>
        <el-table-column prop="workmanshipName" label="工艺路线名称"/>
        <el-table-column prop="workmanshipRouteDescribe" label="工艺路线说明"/>
        <el-table-column prop="workmanshipStatus" label="是否启用">
          <template #default="scope">
            <el-tag type="success" v-if="scope.row.workmanshipStatus == 1">是</el-tag>
            <el-tag type="danger" v-if="scope.row.workmanshipStatus == 2">否</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="workmanshipNotes" label="备注"/>

        <el-table-column label="操作" width="200px">
          <template #default="scope">
            <el-link @click="toEditWorkmanship(scope.row)" style="margin: 0px 5px" type="primary"><el-icon><EditPen /></el-icon>修改</el-link>
            <el-popconfirm width="200"
                           confirm-button-text="必须删"
                           cancel-button-text="点错了"
                           @confirm="deleteWorkmanshipById(scope.row.workmanshipRouteId)"
                           title="您确定要删除这条数据吗？">
              <template  #reference>
                <el-link style="margin: 0px 5px" type="primary">
                  <el-icon><Delete /></el-icon>删除
                </el-link>
              </template>
            </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>
    </el-col>
  </el-row>
  <el-row style="margin: 0px 10px;padding: 0px 15px">
    <el-col :span="24">
      <el-pagination @change="changePage" background layout="prev,pager,next" :total="total"/>
    </el-col>
  </el-row>
<!--新增工艺-->
  <el-dialog v-model="workmanshipAddWinDialogVisible" title="添加工艺路线" width="70%">
    <!--    <template #default>-->
    <el-form :model="newWorkmanship" label-width="auto">
      <el-row>
        <el-col :span="12">
          <el-form-item label="编号">
            <el-input v-model="newWorkmanship.workmanshipRouteId" style="width: 300px"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="名称">
            <el-input v-model="newWorkmanship.workmanshipName"style="width: 300px"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="是否启用">
        <el-radio-group style="width: 100px" v-model="newWorkmanship.workmanshipStatus">
          <el-radio label="是" :value="1"/>
          <el-radio label="否" :value="2"/>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="说明">
        <el-input v-model="newWorkmanship.workmanshipRouteDescribe" type="textarea"/>
      </el-form-item>
      <el-form-item label="备注">
        <el-input v-model="newWorkmanship.workmanshipNotes" type="textarea"/>
      </el-form-item>
    </el-form>
    <!--    </template>-->
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="cancleAdd()">取消</el-button>
        <el-button type="primary" @click="addWorkmanshipSubmit">
          确定
        </el-button>
      </div>
    </template>
  </el-dialog>

  <!--编辑工艺-->
  <el-dialog v-model="workmanshipEditWinDialogVisible" title="修改工艺路线" width="70%">
    <!--    <template #default>-->
    <el-form :model="workmanshipEdit" label-width="auto">
      <el-row>
        <el-col :span="12">
          <el-form-item label="编号">
            <el-input v-model="workmanshipEdit.workmanshipRouteId" style="width: 300px"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="名称">
            <el-input v-model="workmanshipEdit.workmanshipName"style="width: 300px"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="是否启用">
        <el-radio-group style="width: 100px" v-model="workmanshipEdit.workmanshipStatus">
          <el-radio label="是" :value="1"/>
          <el-radio label="否" :value="2"/>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="说明">
        <el-input v-model="workmanshipEdit.workmanshipRouteDescribe" type="textarea"/>
      </el-form-item>
      <el-form-item label="备注">
        <el-input v-model="workmanshipEdit.workmanshipNotes" type="textarea"/>
      </el-form-item>
    </el-form>
<!--    组成工序，关联产品列表-->

    <div>
      <!-- 确保有正确的挂载点 -->
      <router-view></router-view>
      <el-tabs type="border-card">
        <el-tab-pane label="组成工序">
          <!-- 工具栏 -->
          <el-row style="margin: 0px 10px;padding: 0px 10px">
            <el-col :span="24">
              <el-button @click="addNewComposition" type="primary" plain><el-icon><Plus /></el-icon>新增</el-button>
              <el-button @click="" type="success" plain><el-icon><EditPen /></el-icon>修改</el-button>
              <el-button @click="" type="danger" plain><el-icon><Delete /></el-icon>删除</el-button>
              <el-button @click="" type="warning" plain><el-icon><Download /></el-icon>导出</el-button>
            </el-col>
          </el-row>
          <!--  组成工序列表        -->
          <el-row style="margin: 10px 10px;padding:0px 15px;">
            <el-col :span="24">
              <el-table :data="composition" border stripe ref="workmanshipTable">
                <el-table-column type="selection" width="55" fixed="left"/>
                <el-table-column prop="processNumber" label="序号" fixed="left">
                  <template #default="scope">
                    <el-link type="success" @click="">{{scope.row.processNumber}}</el-link>
                  </template>
                </el-table-column>
                <el-table-column prop="processId" label="工序编码" fixed="left"/>
                <el-table-column prop="process.processName" label="工序名称" fixed="left"/>
                <el-table-column prop="nextProcess" label="下一道工序"/>
                <el-table-column prop="workmanshipStatus" label="与下一道工序关系">
                  <template #default="scope">
                    <template v-if="scope.row.processRelationship == 1">S-to-S</template>
                    <template v-if="scope.row.processRelationship == 2">F-to-F</template>
                    <template v-if="scope.row.processRelationship == 3">S-to-F</template>
                    <template v-if="scope.row.processRelationship == 4">F-to-S</template>
                  </template>
                </el-table-column>
                <el-table-column prop="workmanshipStatus" label="关键工序">
                  <template #default="scope">
                    <el-tag type="success" v-if="scope.row.keyProcess == 1">是</el-tag>
                    <el-tag type="danger" v-if="scope.row.keyProcess == 2">否</el-tag>
                  </template>
                </el-table-column>
                <el-table-column prop="workmanshipStatus" label="质检确认">
                  <template #default="scope">
                    <el-tag type="success" v-if="scope.row.qualityConfirm == 1">是</el-tag>
                    <el-tag type="danger" v-if="scope.row.qualityConfirm == 2">否</el-tag>
                  </template>
                </el-table-column>
                <el-table-column prop="preparationTime" label="准备时间"/>
                <el-table-column prop="waitTime" label="等待时间"/>
                <el-table-column label="甘特图显示颜色">
                  <template #default="scope">
                    <div class="demo-color-block">
                      <el-color-picker v-model="scope.row.ganttChartColor" disabled/>
                    </div>
                  </template>
                </el-table-column>
                <el-table-column prop="workmanshipNotes" label="备注"/>

                <el-table-column label="操作" width="200px" fixed="right">
                  <template #default="scope">
                    <el-link @click="toEditComposition(scope.row)" style="margin: 0px 5px" type="primary"><el-icon><EditPen /></el-icon>修改</el-link>
                    <el-popconfirm width="200"
                                   confirm-button-text="必须删"
                                   cancel-button-text="点错了"
                                   @confirm=""
                                   title="您确定要删除这条数据吗？">
                      <template  #reference>
                        <el-link style="margin: 0px 5px" type="primary">
                          <el-icon><Delete /></el-icon>删除
                        </el-link>
                      </template>
                    </el-popconfirm>
                  </template>
                </el-table-column>
              </el-table>
            </el-col>
          </el-row>
          <el-row style="margin: 0px 10px;padding: 0px 15px">
            <el-col :span="24">
              <el-pagination @change="changeComPage" background layout="prev,pager,next" :total="comTotal"/>
            </el-col>
          </el-row>
        </el-tab-pane>
<!--       关联产品 -->
        <el-tab-pane label="关联产品">
          <el-row style="margin: 10px;padding: 15px">
            <el-col :span="24">
              <el-form :model="workmanshipMaterialQuery" inline>
                <el-form-item label="工序编码">
                  <el-input v-model="workmanshipMaterialQuery.materialCode">
                  </el-input>
                </el-form-item>
                <el-form-item label="工序名称">
                  <el-input v-model="workmanshipMaterialQuery.materialName"/>
                </el-form-item>
                <el-form-item>
                  <el-button @click="queryWorkmanshipMaterial" type="primary"><el-icon><Search /></el-icon>搜索</el-button>
                  <el-button @click="clearAllWorkmanshipMaterial"><el-icon><Refresh /></el-icon>清空</el-button>
                </el-form-item>
              </el-form>
            </el-col>
          </el-row>
          <!--   工具栏       -->
          <el-row style="margin: 0px 10px;padding: 0px 10px">
            <el-col :span="24">
              <el-button @click="addNewWorkmanshipMaterial" type="primary" plain><el-icon><Plus /></el-icon>新增</el-button>
              <el-button @click="" type="success" plain><el-icon><EditPen /></el-icon>修改</el-button>
              <el-button @click="" type="danger" plain><el-icon><Delete /></el-icon>删除</el-button>
              <el-button @click="" type="warning" plain><el-icon><Download /></el-icon>导出</el-button>
            </el-col>
          </el-row>
          <el-row style="margin: 10px 10px;padding:0px 15px;">
            <el-col :span="24">
              <el-table :data="workmanshipMaterial" border stripe ref="workmanshipTable">
                <el-table-column type="selection" width="55"/>
                <el-table-column prop="materialCode" label="产品物料编码">
                  <template #default="scope">
                    <el-link type="success" @click="">{{scope.row.materialCode}}</el-link>
                  </template>
                </el-table-column>
                <el-table-column prop="materialName" label="产品物料名称"/>
                <el-table-column prop="specification" label="规格型号"/>
                <el-table-column prop="materialUnitCode" label="单位"/>
                <el-table-column label="操作" width="200px">
                  <template #default="scope">
                    <el-link @click="toEditMaterial(scope.row)" style="margin: 0px 5px" type="primary"><el-icon><EditPen /></el-icon>修改</el-link>
                    <el-popconfirm width="200"
                                   confirm-button-text="必须删"
                                   cancel-button-text="点错了"
                                   @confirm=""
                                   title="您确定要删除这条数据吗？">
                      <template  #reference>
                        <el-link style="margin: 0px 5px" type="primary">
                          <el-icon><Delete /></el-icon>删除
                        </el-link>
                      </template>
                    </el-popconfirm>
                  </template>
                </el-table-column>
              </el-table>
              <el-row style="margin: 0px 10px;padding: 0px 15px">
                <el-col :span="24">
                  <el-pagination @change="changeMaPage" background layout="prev,pager,next" :total="maTotal"/>
                </el-col>
              </el-row>
            </el-col>
          </el-row>
        </el-tab-pane>
      </el-tabs>
    </div>
    <!--    </template>-->
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="cancleEdit()">取消</el-button>
        <el-button type="primary" @click="editWorkmanshipSubmit">
          确定
        </el-button>
      </div>
    </template>
  </el-dialog>
<!--  查看工艺详情-->
  <el-dialog v-model="workmanshipDetailWinDialogVisible" title="查看工艺路线信息" width="80%">
    <!--    <template #default>-->
    <el-form :model="workmanshipDetail" label-width="auto">
      <el-row>
        <el-col :span="12">
          <el-form-item label="编号">
            <el-input v-model="workmanshipDetail.workmanshipRouteId" style="width: 300px" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="名称">
            <el-input v-model="workmanshipDetail.workmanshipName"style="width: 300px" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="是否启用">
        <el-radio-group style="width: 100px" v-model="workmanshipDetail.workmanshipStatus" >
          <el-radio label="是" :value="1"/>
          <el-radio label="否" :value="2"/>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="说明">
        <el-input v-model="workmanshipDetail.workmanshipRouteDescribe" type="textarea"/>
      </el-form-item>
      <el-form-item label="备注">
        <el-input v-model="workmanshipDetail.workmanshipNotes" type="textarea"/>
      </el-form-item>
    </el-form>
    <!--    组成工序，关联产品列表-->
    <div>
      <!-- 确保有正确的挂载点 -->
      <router-view></router-view>
      <el-tabs type="border-card">
        <el-tab-pane label="组成工序">
          <!--  组成工序列表        -->
          <el-row style="margin: 10px 10px;padding:0px 15px;">
            <el-col :span="24">
              <el-table :data="composition" border stripe ref="workmanshipTable">
                <el-table-column type="selection" width="55" fixed="left"/>
                <el-table-column prop="processNumber" label="序号" fixed="left">
                  <template #default="scope">
                    <el-link type="success" @click="">{{scope.row.processNumber}}</el-link>
                  </template>
                </el-table-column>
                <el-table-column prop="processId" label="工序编码" fixed="left"/>
                <el-table-column prop="process.processName" label="工序名称" fixed="left"/>
                <el-table-column prop="nextProcess" label="下一道工序"/>
                <el-table-column prop="workmanshipStatus" label="与下一道工序关系">
                  <template #default="scope">
                    <template v-if="scope.row.processRelationship == 1">S-to-S</template>
                    <template v-if="scope.row.processRelationship == 2">F-to-F</template>
                    <template v-if="scope.row.processRelationship == 3">S-to-F</template>
                    <template v-if="scope.row.processRelationship == 4">F-to-S</template>
                  </template>
                </el-table-column>
                <el-table-column prop="workmanshipStatus" label="关键工序">
                  <template #default="scope">
                    <el-tag type="success" v-if="scope.row.keyProcess == 1">是</el-tag>
                    <el-tag type="danger" v-if="scope.row.keyProcess == 2">否</el-tag>
                  </template>
                </el-table-column>
                <el-table-column prop="workmanshipStatus" label="质检确认">
                  <template #default="scope">
                    <el-tag type="success" v-if="scope.row.qualityConfirm == 1">是</el-tag>
                    <el-tag type="danger" v-if="scope.row.qualityConfirm == 2">否</el-tag>
                  </template>
                </el-table-column>
                <el-table-column prop="preparationTime" label="准备时间"/>
                <el-table-column prop="waitTime" label="等待时间"/>
                <el-table-column label="甘特图显示颜色">
                  <template #default="scope">
                    <div class="demo-color-block">
                      <el-color-picker v-model="scope.row.ganttChartColor" disabled/>
                    </div>
                  </template>
                </el-table-column>
                <el-table-column prop="workmanshipNotes" label="备注"/>
              </el-table>
            </el-col>
          </el-row>
          <el-row style="margin: 0px 10px;padding: 0px 15px">
            <el-col :span="24">
              <el-pagination @change="changeComPage" background layout="prev,pager,next" :total="comTotal"/>
            </el-col>
          </el-row>
        </el-tab-pane>
        <!--       关联产品 -->
        <el-tab-pane label="关联产品">
          <el-row style="margin: 10px;padding: 15px">
            <el-col :span="24">
              <el-form :model="workmanshipMaterialQuery" inline>
                <el-form-item label="工序编码">
                  <el-input v-model="workmanshipMaterialQuery.materialCode">
                  </el-input>
                </el-form-item>
                <el-form-item label="工序名称">
                  <el-input v-model="workmanshipMaterialQuery.materialName"/>
                </el-form-item>
                <el-form-item>
                  <el-button @click="queryWorkmanshipMaterial" type="primary"><el-icon><Search /></el-icon>搜索</el-button>
                  <el-button @click="clearAllWorkmanshipMaterial"><el-icon><Refresh /></el-icon>清空</el-button>
                </el-form-item>
              </el-form>
            </el-col>
          </el-row>
          <el-row style="margin: 10px 10px;padding:0px 15px;">
            <el-col :span="24">
              <el-table :data="workmanshipMaterial" border stripe ref="workmanshipTable">
                <el-table-column type="selection" width="55"/>
                <el-table-column prop="materialCode" label="产品物料编码">
                  <template #default="scope">
                    <el-link type="success" @click="">{{scope.row.materialCode}}</el-link>
                  </template>
                </el-table-column>
                <el-table-column prop="materialName" label="产品物料名称"/>
                <el-table-column prop="specification" label="规格型号"/>
                <el-table-column prop="materialUnitCode" label="单位"/>
              </el-table>
              <el-row style="margin: 0px 10px;padding: 0px 15px">
                <el-col :span="24">
                  <el-pagination @change="changeMaPage" background layout="prev,pager,next" :total="maTotal"/>
                </el-col>
              </el-row>
            </el-col>
          </el-row>
        </el-tab-pane>
      </el-tabs>
    </div>
  </el-dialog>

  <!--  添加组成工序-->
  <el-dialog v-model="compositionAddWinDialogVisible" title="添加工艺组成" width="70%">
    <!--    <template #default>-->
    <el-form :model="addComposition" label-width="auto">
      <el-row>
        <el-col :span="12">
          <el-form-item label="序号">
            <el-input-number  v-model="addComposition.processNumber" :min="0"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="工序">
            <el-select
                v-model="addComposition.processId"
                placeholder="请选择工序"
                style="width: 240px"
            >
              <el-option
                  v-for="process in processes"
                  :key="process.processId"
                  :label="process.processName"
                  :value="process.processId"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="与下一道工序关系">
                <el-select
                    v-model="addComposition.processRelationship"
                    placeholder="请选择工序"
                    style="width: 240px"
                >
                  <el-option
                      v-for="relationship in relationships"
                      :key="relationship.relationshipId"
                      :label="relationship.relationship"
                      :value="relationship.relationshipId"
                  />
                </el-select>
            </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="甘特图显示颜色">
                <div class="demo-color-block">
                  <el-color-picker v-model="addComposition.ganttChartColor" />
                </div>
            <el-input v-model="addComposition.ganttChartColor"style="width: 300px" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="是否关键工序">
            <el-select style="width: 100px" v-model="addComposition.keyProcess" >
              <el-option
                  v-for="statu in status"
                  :key="statu.statusId"
                  :label="statu.status"
                  :value="statu.statusId"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="是否需要质检确认">
            <el-select style="width: 100px" v-model="addComposition.qualityConfirm" >
              <el-option
                  v-for="statu in status"
                  :key="statu.statusId"
                  :label="statu.status"
                  :value="statu.statusId"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="准备时间">
            <el-input-number  v-model="addComposition.preparationTime" :min="0"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="等待时间">
            <el-input-number  v-model="addComposition.waitTime" :min="0"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="备注">
        <el-input v-model="addComposition.workmanshipCompositionNotes" type="textarea"/>
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="cancleAddCom()">取消</el-button>
        <el-button type="primary" @click="addWorkmanshipCompositionSubmit">
          确定
        </el-button>
      </div>
    </template>
  </el-dialog>

  <!--  修改组成工序-->
  <el-dialog v-model="compositionEditWinDialogVisible" title="修改工艺组成" width="70%">
    <!--    <template #default>-->
    <el-form :model="compostitionEdit" label-width="auto">
      <el-row>
        <el-col :span="12">
          <el-form-item label="序号">
            <el-input-number  v-model="compostitionEdit.processNumber" :min="0"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="工序">
            <el-select
                v-model="compostitionEdit.processId"
                placeholder="请选择工序"
                style="width: 240px"
            >
              <el-option
                  v-for="process in processes"
                  :key="process.processId"
                  :label="process.processName"
                  :value="process.processId"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="与下一道工序关系">
            <el-select
                v-model="compostitionEdit.processRelationship"
                placeholder="请选择工序"
                style="width: 240px"
            >
              <el-option
                  v-for="relationship in relationships"
                  :key="relationship.relationshipId"
                  :label="relationship.relationship"
                  :value="relationship.relationshipId"
              />
            </el-select>
            <!--              </el-tooltip>-->
            <!--            <el-input v-model="addComposition.workmanshipName"style="width: 300px" />-->
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="甘特图显示颜色">
            <div class="demo-color-block">
              <el-color-picker v-model="compostitionEdit.ganttChartColor" />
            </div>
            <el-input v-model="compostitionEdit.ganttChartColor"style="width: 300px" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="是否关键工序">
            <el-select style="width: 100px" v-model="compostitionEdit.keyProcess" >
              <el-option
                  v-for="statu in status"
                  :key="statu.statusId"
                  :label="statu.status"
                  :value="statu.statusId"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="是否需要质检确认">
            <el-select style="width: 100px" v-model="compostitionEdit.qualityConfirm" >
              <el-option
                  v-for="statu in status"
                  :key="statu.statusId"
                  :label="statu.status"
                  :value="statu.statusId"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="准备时间">
            <el-input-number  v-model="compostitionEdit.preparationTime" :min="0"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="等待时间">
            <el-input-number  v-model="compostitionEdit.waitTime" :min="0"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="备注">
        <el-input v-model="compostitionEdit.workmanshipCompositionNotes" type="textarea"/>
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="cancleEditCom()">取消</el-button>
        <el-button type="primary" @click="editWorkmanshipCompositionSubmit">
          确定
        </el-button>
      </div>
    </template>
  </el-dialog>
<!--添加关联产品-->
  <el-dialog v-model="materialAddWinDialogVisible" title="添加关联产品" width="70%">
    <!--    <template #default>-->
    <el-form :model="newMaterial" label-width="auto">
      <el-row>
        <el-col :span="12">
          <el-form-item label="产品物料编码">
            <el-input v-model="newMaterial.materialCode" disabled/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="产品物料名称">
            <el-select
                v-model="newMaterial.materialCode"
                @change="onMaterialSelected"
                placeholder="请选择产品"
                style="width: 240px"
            >
              <el-option
                  v-for="material in materials"
                  :key="material.materialCode"
                  :label="material.materialName"
                  :value="material.materialCode"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="单位">
            <el-input v-model="newMaterial.materialUnitCode" disabled/>
           </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="规格型号">
            <el-input v-model="newMaterial.specification"style="width: 300px" disabled/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="备注">
        <el-input v-model="newMaterial.manufacturingNotes" type="textarea"/>
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="cancleAddMat()">取消</el-button>
        <el-button type="primary" @click="addWorkmanshipMaterialSubmit">
          确定
        </el-button>
      </div>
    </template>
  </el-dialog>
  <!--  修改关联产品-->
  <el-dialog v-model="materialEditWinDialogVisible" title="修改关联产品" width="70%">
    <!--    <template #default>-->
    <el-form :model="materialDetail" label-width="auto">
      <el-row>
        <el-col :span="12">
          <el-form-item label="产品物料编码">
            <el-input v-model="materialDetail.materialCode" disabled/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="产品物料名称">
            <el-select
                v-model="materialDetail.materialCode"
                @change="onMaterialSelectedEdit"
                placeholder="请选择产品"
                style="width: 240px"
            >
              <el-option
                  v-for="material in materials"
                  :key="material.materialCode"
                  :label="material.materialName"
                  :value="material.materialCode"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="单位">
            <el-input v-model="materialDetail.materialUnitCode" disabled/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="规格型号">
            <el-input v-model="materialDetail.specification"style="width: 300px" disabled/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="备注">
        <el-input v-model="materialDetail.manufacturingNotes" type="textarea"/>
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="cancleAddMat()">取消</el-button>
        <el-button type="primary" @click="editWorkmanshipMaterialSubmit">
          确定
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<style scoped>

</style>

<script setup>
import workmanshipRequest from "@/api/workmanship.js";
import {onMounted, ref} from "vue";
import {ElMessage, ElMessageBox} from "element-plus";
import workmanshipCompositionRequest from "@/api/workmanshipComposition.js";
import processRequest from "@/api/process.js";
import processRelationshipRequest from "@/api/processRelationship.js";
import workmanshipMaterialRequest from "@/api/workmanshipMaterial.js";
import materialRequest from "@/api/material.js";
let pageNum = ref(1);
let total = ref(0);
let workmanshipQuery = ref({});
let workmanships = ref([]);
let workmanshipAddWinDialogVisible = ref(false);
let newWorkmanship = ref({workmanshipStatus: 1});
let workmanshipEditWinDialogVisible = ref(false);
let workmanshipDetailWinDialogVisible = ref(false);
let compositionAddWinDialogVisible = ref(false);
let compositionEditWinDialogVisible = ref(false);
let materialAddWinDialogVisible = ref(false);
let materialEditWinDialogVisible = ref(false);
let workmanshipDetail = ref({});
let workmanshipEdit = ref({});
let workmanshipTable = ref(null);
let comPageNum = ref(1);
let comTotal = ref(0);
let composition = ref([]);
let addComposition = ref({processNumber:1,qualityConfirm:0,ganttChartColor:'#0a0ab9',preparationTime:0,waitTime:0});
let processes = ref([]);
let relationships=ref([]);
let status = ref([
  {
    statusId:0,
    status:'否'
  },{
    statusId:1,
    status:'是'
  }
]);
let compostitionEdit = ref({});
let workmanshipMaterialQuery = ref({});
let workmanshipMaterial = ref([]);
let maPageNum = ref(1);
let maTotal = ref(0);
let materials = ref([]);
let newMaterial = ref({});
let workmanshipId = ref();
let materialDetail = ref({});
function toEditMaterial(material){
  let queryM = ref({});
  queryM.value = material;
  queryM.value.workmanshipId = workmanshipId.value;
  console.log(queryM.value);
  workmanshipMaterialRequest.listById(queryM.value,res=>{
    console.log(res);
    materialDetail.value = res.data;
  })
  materialRequest.getAllMaterial(res=>{
    console.log(res.data)
    materials.value = res.data;
  })
  materialEditWinDialogVisible.value = true;

}
function onMaterialSelectedEdit(code){
  let selectedMaterial = materials.value.find(material => material.materialCode === code);
  if (selectedMaterial) {
    materialDetail.value.materialName = selectedMaterial.materialName;
    materialDetail.value.materialUnitCode = selectedMaterial.materialUnitCode;
    materialDetail.value.specification = selectedMaterial.specification;
    materialDetail.value.materialId = selectedMaterial.materialId;
  }
  console.log(newMaterial.value);
}
function editWorkmanshipMaterialSubmit(){
  materialDetail.value.workmanshipId = workmanshipId.value;
  console.log(materialDetail.value);
  workmanshipMaterialRequest.edit(materialDetail.value,res=>{
    console.log(res);
    if(res.code == 200){
      ElMessage({
        type:"success",
        message:"修改成功"
      });
      loadWorknamshipMaterial(workmanshipId.value);
      materialEditWinDialogVisible.value = false;
    }
  })
}
function addWorkmanshipMaterialSubmit(){
  console.log(compostitionEdit.value.workmanshipId);
  newMaterial.value.workmanshipId = workmanshipId.value;
  if(newMaterial.value.materialId == null){
    alert("还没有选择！")
    return;
  }
  console.log(newMaterial.value)
  workmanshipMaterialRequest.add(newMaterial.value,res=>{
    console.log(res);
    if(res.code == 200){
        ElMessage({
          type:"success",
          message:"保存成功"
        });
        loadWorknamshipMaterial(workmanshipId.value);
        materialAddWinDialogVisible.value = false;
    }else if(res.code == 300){
      ElMessage({
        type:"warning",
        message:"此产品已配置了工艺路线"
      });
    }
  })
}
function cancleAddMat(){
  materialAddWinDialogVisible.value = false;
  newMaterial = ref({});
}
function addNewWorkmanshipMaterial(){
  materialAddWinDialogVisible.value = true;
  materialRequest.getAllMaterial(res=>{
    console.log(res.data)
    materials.value = res.data;
  })
}
function onMaterialSelected(code){
  let selectedMaterial = materials.value.find(material => material.materialCode === code);
  if (selectedMaterial) {
    newMaterial.value.materialName = selectedMaterial.materialName;
    newMaterial.value.materialUnitCode = selectedMaterial.materialUnitCode;
    newMaterial.value.specification = selectedMaterial.specification;
    newMaterial.value.materialId = selectedMaterial.materialId;
  }
  console.log(newMaterial.value);
}
function queryWorkmanshipMaterial(){
  loadWorknamshipMaterial(workmanshipId.value);
}
function clearAllWorkmanshipMaterial(){
  workmanshipMaterialQuery.value = {};
  loadWorknamshipMaterial(workmanshipId.value);
}
function loadWorknamshipMaterial(workmanshipId){
  workmanshipMaterialQuery.value.workmanshipId = workmanshipId;
  workmanshipMaterialRequest.list(workmanshipMaterialQuery.value,maPageNum.value,10,res=>{
    console.log(res);
    maTotal.value = res.total;
    workmanshipMaterial.value = res.data.list;
  })
}
function changeMaPage(value){
  maPageNum.value = value;
  loadWorknamshipMaterial(workmanshipEdit.value.workmanshipId)
}
function toEditComposition(compositionValue){
  workmanshipCompositionRequest.query(compositionValue.workmanshipId,compositionValue.processNumber,res=>{
    console.log(res)
    compostitionEdit.value = res.data;
    console.log("-----------------")
    console.log(compostitionEdit.value)
  })
  compositionEditWinDialogVisible.value = true;
}
function editWorkmanshipCompositionSubmit(){
  workmanshipCompositionRequest.edit(compostitionEdit.value,res=>{
    console.log(res);
    ElMessage({
      type:"success",
      message:"保存成功"
    });
    compositionEditWinDialogVisible.value = false;
    loadComposition(compostitionEdit.value.workmanshipId);
  })
}

function cancleAddCom(){
  compositionAddWinDialogVisible.value = false;
  addComposition = ref({});
}
function cancleEditCom(){
  compositionEditWinDialogVisible.value = false;
  // loadComposition(compostitionEdit.value.workmanshipId);
}
function addNewComposition(){
  compositionAddWinDialogVisible.value = true;
  addComposition = ref({processNumber:1,qualityConfirm:0,ganttChartColor:'#0a0ab9',preparationTime:0,waitTime:0});
  addComposition.value.workmanshipId = workmanshipEdit.value.workmanshipId;
}
function addWorkmanshipCompositionSubmit(){
  console.log(addComposition.value.target)
  if(addComposition.value.processId == null){
    alert("请选择工序！");
    return;
  }
  if(addComposition.value.keyProcess == null){
    alert("请选择是否关键工序！");
    return;
  }
  if(addComposition.value.qualityConfirm == null){
    alert("请选择是否需要质检确认！");
    return;
  }
  console.log(addComposition.value);
  workmanshipCompositionRequest.add(addComposition.value,res=>{
    console.log(res);
    if(res.code == 200){
      ElMessage({
        type:"success",
        message:"保存成功"
      });
      loadComposition(addComposition.value.workmanshipId);
    }

  })
  compositionAddWinDialogVisible.value = false;
}
function loadComposition(workmanshipId){
  workmanshipCompositionRequest.list(workmanshipId,comPageNum.value,10,res=>{
    console.log(res);
    comTotal.value = res.data.total;
    composition.value = res.data.list;
    console.log(composition.value);
  })
}

function reDelete(){
  let selectedRows = workmanshipTable.value.getSelectionRows();
  if(selectedRows.length == 0){
    ElMessage({
      type:"warning",
      message:"你没有选中任何数据"
    });
    return;
  }
  ElMessageBox.confirm(
      '您确定要将选中的项目删除吗？',
      '提示',
      {
        confirmButtonText:'是的',
        cancelButtonText:'点错了',
        type:'warning',
      }
  ).then(()=>{
    let workmanshipRouteIds = [];
    selectedRows.forEach(row=>{
      workmanshipRouteIds.push(row.workmanshipRouteId);
    });
    console.log(workmanshipRouteIds);
    workmanshipRequest.reDelete(workmanshipRouteIds,res=>{
      console.log(res);
      if(res.code == 200){
        ElMessage({
          type:"success",
          message:"删除成功"
        });
        loadWorkmanship();
      }
    })
  }).catch(()=>{})
}
function showDetails(workmanship){
  workmanshipDetail.value = workmanship;
  workmanshipDetailWinDialogVisible.value = true;
}
function editWorkmanshipSubmit(){
  if(!workmanshipEdit.value.workmanshipRouteId){
    alert("编号不能为空！");
    return;
  }
  if(workmanshipEdit.value.workmanshipName == null){
    alert("名称不能为空！");
    return;
  }
  workmanshipRequest.editWorkmanship(workmanshipEdit.value,res=>{
    if(res.code == 200){
      ElMessage({
        type:"success",
        message:"保存成功"
      });
      loadWorkmanship();
      workmanshipEditWinDialogVisible.value = false;
    }else {
      ElMessage({
        type:"warning",
        message:"编码已存在！"
      });
    }
  })
}
function cancleEdit(){
  workmanshipEditWinDialogVisible.value = false;
  workmanshipEdit = ref({});
}
function toEditWorkmanship(workmanship){
  workmanshipId.value = workmanship.workmanshipId;
  loadComposition(workmanship.workmanshipId);
  loadWorknamshipMaterial(workmanship.workmanshipId);
  workmanshipEditWinDialogVisible.value = true;
  processRequest.listAll(res=>{
    console.log(res)
    processes.value = res.data;
    console.log(processes.value);
  })
  processRelationshipRequest.list(res=>{
    relationships.value = res.data;
  })
  workmanshipRequest.showByWorkmanshipId(workmanship.workmanshipId,res=>{
    workmanshipEdit.value = res.data;
  })
  // workmanshipEdit.value = workmanship;
}
function deleteWorkmanshipById(workmanshipRouteId){
  workmanshipRequest.deleteWorkmanship(workmanshipRouteId,res=>{
    if(res.code == 200){
      ElMessage({
        type:"success",
        message:"保存成功"
      });
      loadWorkmanship();
    }
  })
}
function cancleAdd(){
  workmanshipAddWinDialogVisible.value = false;
  newWorkmanship = ref({workmanshipStatus: 1});
}
function addWorkmanship(){
  workmanshipAddWinDialogVisible.value = true;
}
function addWorkmanshipSubmit(){
  if(!newWorkmanship.value.workmanshipRouteId){
    alert("编号不能为空！");
    return;
  }
  if(newWorkmanship.value.workmanshipName == null){
    alert("名称不能为空！");
    return;
  }
workmanshipRequest.addNewWorkmanship(newWorkmanship.value,res=>{
  console.log(res);
  if(res.code == 200){
    ElMessage({
      type:"success",
      message:"保存成功"
    });
    loadWorkmanship();
    workmanshipAddWinDialogVisible.value = false;
    newWorkmanship = ref({newWorkmanship:1});
  }
})
}
function changePage(value) {
  pageNum.value = value;
  loadWorkmanship();
}
function changeComPage(value){
  comPageNum.value = value;
  loadComposition(workmanshipEdit.value.workmanshipId)
}
function clearAll(){
  workmanshipQuery.value = ref({});
  loadWorkmanship();
}
function loadWorkmanship(){
  workmanshipRequest.loadWorkmanship(workmanshipQuery.value,pageNum.value,10,res=>{
    console.log(res);
    workmanships.value = res.data.list;
    total.value = res.data.total;
  })
}
onMounted(()=>{
  loadWorkmanship();
  changePage();
})
</script>